package com.zmzncs.lmtc.module.shop.pojo.shop_ticket;

import com.zmzncs.lmtc.common.util.ExceptionUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * <p>
 * 商户-优惠券
 * </p>
 *
 * @author 高博文
 * @since 2021-05-20
 */
@Data
public class ShopTicketAddForm implements Serializable {

    private static final long serialVersionUID=1L;


    @ApiModelProperty(value = "商户id",required = true)
    @NotNull
    private Long shopId;

    @ApiModelProperty(value = "最低消费金额",required = true)
    private BigDecimal minimumMoney;

    @ApiModelProperty(value = "优惠券名称",required = true)
    @NotNull
    @Size(max = 15)
    private String ticketName;

    @ApiModelProperty(value = "满减金额",required = true)
    private BigDecimal offsetMoney;

    @ApiModelProperty(value = "折率",required = true)
    @Max(value = 100)
    private BigDecimal discountRate;

    @ApiModelProperty(value = "优惠类型（1：满减，2：折扣）",required = true)
    @NotNull
    private Integer preferentialType;

    @ApiModelProperty(value = "有效期天数",required = true)
    @Max(value = 2147483647)
    private Integer expiryDays;

    @ApiModelProperty(value = "库存",required = true)
    @NotNull
    @Max(value = 2147483647)
    private Integer stock;

    @ApiModelProperty(value = "是否限购（0：否，1：是）",required = true)
    @NotNull
    private Integer isLimitQuantity;

    @ApiModelProperty(value = "限购数量",required = true)
    @Max(value = 2147483647)
    private Integer limitQuantity;

    @ApiModelProperty(value = "有效期",required = true)
    @Max(value = 2147483647)
    private Integer expireDate;

    @ApiModelProperty(value = "是否永久（0：否，1：是）",required = true)
    @NotNull
    private Integer isPermanent;

//    @ApiModelProperty(value = "宣传图片",required = true)
//    @NotNull
//    private List<String> imageList;

    public void validate(){

        //判断限购数量
        if (isLimitQuantity.equals(1) && limitQuantity == null) {
            ExceptionUtil.paramException("限购，限购数量不能为空");
        }

        //判断有效期天数
        if (isPermanent.equals(0) && expireDate == null){
            ExceptionUtil.paramException("非永久，有效期天数不能为空");
        }

        //折扣
        if (preferentialType.equals(1) && discountRate == null){
            ExceptionUtil.paramException("折扣，折率不能为空");
        }

        //满减
        if (preferentialType.equals(2) && offsetMoney == null){
            ExceptionUtil.paramException("满减，满减金额不能为空");
        }
    }

}
